Trò chơi Angry Birds trong UNITY Engine
31.701 lượt xem;
- Vector3YTweenProperty.cs
- genericTypes /
- properties /
- GoKit /
- Plugins /
- Assets /
- project /
1 using UnityEngine;
2 using System;
3 using System.Collections;
4
5
6 public class Vector3YTweenProperty : Vector3XTweenProperty
7 {
8 public Vector3YTweenProperty( string propertyName, float endValue, bool isRelative = false ) : base( propertyName, endValue, isRelative )
9 {}
10
11
12 public override void prepareForUse()
13 {
14 // retrieve the getter
15 _getter = GoTweenUtils.getterForProperty<Func<Vector3>>( _ownerTween.target, propertyName );
16
17 _endValue = _originalEndValue;
18
19 // if this is a from tween we need to swap the start and end values
20 if( _ownerTween.isFrom )
21 {
22 _startValue = _endValue;
23 _endValue = _getter().y;
24 }
25 else
26 {
27 _startValue = _getter().y;
28 }
29
30 // prep the diff value
31 if( _isRelative && !_ownerTween.isFrom )
32 _diffValue = _endValue;
33 else
34 _diffValue = _endValue - _startValue;
35 }
36
37
38 public override void tick( float totalElapsedTime )
39 {
40 var currentValue = _getter();
41 currentValue.y = _easeFunction( totalElapsedTime, _startValue, _diffValue, _ownerTween.duration );
42
43 _setter( currentValue );
44 }
45
46 }
2 using System;
3 using System.Collections;
4
5
6 public class Vector3YTweenProperty : Vector3XTweenProperty
7 {
8 public Vector3YTweenProperty( string propertyName, float endValue, bool isRelative = false ) : base( propertyName, endValue, isRelative )
9 {}
10
11
12 public override void prepareForUse()
13 {
14 // retrieve the getter
15 _getter = GoTweenUtils.getterForProperty<Func<Vector3>>( _ownerTween.target, propertyName );
16
17 _endValue = _originalEndValue;
18
19 // if this is a from tween we need to swap the start and end values
20 if( _ownerTween.isFrom )
21 {
22 _startValue = _endValue;
23 _endValue = _getter().y;
24 }
25 else
26 {
27 _startValue = _getter().y;
28 }
29
30 // prep the diff value
31 if( _isRelative && !_ownerTween.isFrom )
32 _diffValue = _endValue;
33 else
34 _diffValue = _endValue - _startValue;
35 }
36
37
38 public override void tick( float totalElapsedTime )
39 {
40 var currentValue = _getter();
41 currentValue.y = _easeFunction( totalElapsedTime, _startValue, _diffValue, _ownerTween.duration );
42
43 _setter( currentValue );
44 }
45
46 }